import 'package:app_health/pages/home/HomeFirstPage.dart';
import 'package:app_health/pages/home/MePage.dart';
import 'package:flutter/material.dart';

/**
 * 首页
 */
class HomePageWidget extends StatefulWidget {
  static start(BuildContext context) {
    Navigator.push(
        context, MaterialPageRoute(builder: (context) => new HomePageWidget()));
  }

  @override
  State<StatefulWidget> createState() {
    return HomeStateWidget();
  }
}

class HomeStateWidget extends State<HomePageWidget> {
  /// 初始化
  @override
  void initState() {
    super.initState();
    list..add(HomeFirstWidget())..add(MeWidget());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        backgroundColor: Color(0xFF0AD0B2),
        onPressed: () {
          Navigator.of(context)
              .push(MaterialPageRoute(builder: (BuildContext context) {
            return MeWidget();
          }));
        },
        child: Icon(Icons.add),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      body: list[_index],
      bottomNavigationBar: BottomAppBar(
        shape: CircularNotchedRectangle(),
        child: tabs(),
      ),
    );
  }

  int _index = 0;
  List<Widget> list = new List();
  Color _tabColor = Color(0xFF0AD0B2);
  Color _tabColorRight = Colors.grey;

// 底部导航栏
  Row tabs() {
    return Row(
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: <Widget>[
        Padding(
          padding: EdgeInsets.only(top: 10.0, bottom: 10.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              GestureDetector(
                child: Icon(
                  Icons.home,
                  color: _tabColor,
                ),
                onTap: () {
                  setState(() {
                    _tabColor = Color(0xFF0AD0B2);
                    _tabColorRight = Colors.grey;
                    _index = 0;
                  });
                },
              ),
              Text(
                "首页",
                style: TextStyle(color: _tabColor, fontSize: 12.0),
              )
            ],
          ),
        ),
        Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            GestureDetector(
              child: Icon(
                Icons.person,
                color: _tabColorRight,
              ),
              onTap: () {
                setState(() {
                  _tabColor = Colors.grey;
                  _tabColorRight = Color(0xFF0AD0B2);
                  _index = 1;
                });
              },
            ),
            Text("我的", style: TextStyle(color: _tabColorRight, fontSize: 12.0))
          ],
        )
      ],
    );
  }
}
